package cn.herlioner.service;

import java.util.List;

public class PageService<E> {
	//指定的或是页面参�? 
    private Long currentPage;//当前�? 
    private int pageSize;//每页显示多少�? 
      
    //查询数据�? 
    private int recordCount;//总记录数  
    private List recordList;//本页的数据列�? 
    
	//计算  
    private int pageCount;//总页�? 
    private int beginPageIndex;//页码列表的开始索�? 
    private int endPageIndex;//页码列表的结束索�? 
    
    
    /** 
     * 只接受前4个必要的属�?，会自动计算出其�?个属性的�?
     * @param pageNum 	当前�?
     * @param pageSize 		每页多少�?
     * @param recordCount 	总记录数
     * @param recordList 	本页的数据列�?
     */  
    public PageService(int pageNum, int pageSize, int recordCount,  
            List recordList) {  
        this.currentPage = (long) pageNum;  
        this.pageSize = pageSize;  
        this.recordCount = recordCount;  
        this.recordList = recordList;  
        
        //计算总页�? 
        pageCount = (recordCount + pageSize - 1) / pageSize;  
          
        //计算beginPageIndex �?endPageIndex         
        //>>总页数不多于10页，则全部显�? 
        if(pageCount <= 10){  
            beginPageIndex = 1;  
            endPageIndex = pageCount;  
        }  
        //总页数多�?0页，则显示当前页附近的共10个页�? 
        else{  
            //当前页附近的�?0个页码（�?�?当前�?�?个）  
            beginPageIndex = pageNum - 4;  
            endPageIndex = pageNum + 5;  
              
            //当前面的页码不足4个时，则显示�?0个页�? 
            if(beginPageIndex < 1){  
                beginPageIndex = 1;  
                endPageIndex = 10;  
            }  
            //当后面的页码不足5个时，则显示�?0个页�? 
            if(endPageIndex > pageCount){  
                endPageIndex = pageCount;  
                beginPageIndex = pageCount -10 + 1;  
            }  
        }  
              
    }
    
    public PageService(){}
    
    @Override
	public String toString() {
		return "PageBean [currentPage=" + currentPage + ", pageSize="
				+ pageSize + ", recordCount=" + recordCount + ", recordList="
				+ recordList + ", pageCount=" + pageCount + ", beginPageIndex="
				+ beginPageIndex + ", endPageIndex=" + endPageIndex + "]";
	}

	//get,set  
    
    public Long getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = (long) currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public List getRecordList() {
		return recordList;
	}

	public void setRecordList(List recordList) {
		this.recordList = recordList;
	}
	
	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getBeginPageIndex() {
		return beginPageIndex;
	}

	public void setBeginPageIndex(int beginPageIndex) {
		this.beginPageIndex = beginPageIndex;
	}

	public int getEndPageIndex() {
		return endPageIndex;
	}

	public void setEndPageIndex(int endPageIndex) {
		this.endPageIndex = endPageIndex;
	}  
      

    
}  

